package com.lagou.ModelTest3.First.Three;

import java.util.*;

public class StudentTest {
    public static void main(String[] args) {
        Set<Student> s1=new LinkedHashSet<>();
        s1.add(new Student("张飞", 30));
        s1.add(new Student("关羽",35));
        s1.add(new Student("刘备",40));
        System.out.println("Set集合:"+s1);
        System.out.println("____________________________________________________________");
        //定义Map集合，用Student对象作为key，用字符串(此表示表示学生的住址)作为value
        Map<Student,String> m1=new LinkedHashMap<>();
        m1.put(new Student("张飞", 30),"1001");
        m1.put(new Student("关羽", 35),"1002");
        m1.put(new Student("刘备", 40),"1003");
        System.out.println("Map集合:"+m1);
        System.out.println("____________________________________________________________");
        //利用四种方式遍历Map集合中的内容，格式：key:value
        //第一种:toString方法，就是上面的方法
        //第二种
        Set<Student> s2=m1.keySet();
        for(Student key:s2){
            System.out.println(key+":"+m1.get(key));
        }
        System.out.println("____________________________________________________________");
        //第三种
        Collection<String> co=m1.values();
        for(String key:co){
            System.out.println("values="+key);
        }
        System.out.println("____________________________________________________________");
        //第四种
        Set<Map.Entry<Student,String>> entries=m1.entrySet();
        for(Map.Entry<Student,String> key:entries){
            System.out.println(key);
        }

    }
}
